/// ===========================================================================
/// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
/// KIND, WHETHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
/// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
/// PURPOSE.
/// ===========================================================================
/// 
/// Project:        MOSS Faceted Search
/// Author:         Leonid Lyublinski (leonidly@microsoft.com)
/// Company:        Microsoft Services
/// Date:           05/04/2007      Version:        1.0 
///
/// ===========================================================================

using System;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
using System.Xml.Serialization;
using System.Data;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.Office.Server;
using Microsoft.Office.Server.Search.Query;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.Portal.ExtendedSearch.Common;

namespace Microsoft.SharePoint.Portal.ExtendedSearch.WebControls
{

    /// <summary>
    /// Class defines templates used for facet data binding
    /// </summary>
    public class FacetTemplate : Control, INamingContainer, ITemplate
    {
        #region fields
        private ListItemType _type;
        private string _cssClass;
        private short _cropMax = 20;
        private readonly string IMAGES_FOLDER = "~/_layouts/images/";
        #endregion

        #region ctor
        public FacetTemplate(ListItemType type, string cssClass)
        {
            _type = type;
            _cssClass = cssClass;
        }

        public FacetTemplate(ListItemType type, string cssClass, short cropMax)
        {
            _type = type;
            _cssClass = cssClass;
            _cropMax = cropMax;
        } 
        #endregion

        #region ITemplate Members
        public void InstantiateIn(Control container)
        {
            LinkButton link = new LinkButton();
            link.CssClass = _cssClass;
            link.Style.Add("vertical-align", "middle");
            Label hits = new Label();
            //hits.CssClass = _cssClass;
            HtmlImage img = new HtmlImage();
            img.EnableViewState = false;
            img.Visible = false;
            img.Align = "absmiddle";
            img.Style.Add("MARGIN-RIGHT", "6px");

            switch (_type)
            {
                case ListItemType.Header:
                    break;
                case ListItemType.Item:
                    link.DataBinding += new EventHandler(link_DataBinding);
                    container.Controls.Add(new LiteralControl(@"
                        <table border=""0"" cellpadding=""0"" cellspacing=""0"" class=""" + _cssClass + @""" width=""100%"">
                            <tr>
                                <td nowrap=""nowrap"" width=""100%"" style=""vertical-align:middle"">"));
                    container.Controls.Add(img);                    
                    container.Controls.Add(link);
                    container.Controls.Add(hits);
                    container.Controls.Add(new LiteralControl(@"</td></tr></table>"));

                    img.DataBinding += new EventHandler(img_DataBinding);
                    hits.DataBinding += new EventHandler(hits_DataBinding);
                    //container.Controls.Add(new LiteralControl("</li>"));
                    break;
                case ListItemType.AlternatingItem:
                    break;
                case ListItemType.Footer:
                    break;
            }
        }

        void img_DataBinding(object sender, EventArgs e)
        {
            HtmlImage img = (HtmlImage)sender;
            IDataItemContainer container = (IDataItemContainer)img.NamingContainer;
            Facet facet = (Facet)container.DataItem;
            if (string.IsNullOrEmpty(facet.Image))
            {
                img.Visible = false;
            }
            else
            {
                img.Visible = true;
                img.Src = IMAGES_FOLDER + facet.Image;
            }
        }

        void hits_DataBinding(object sender, EventArgs e)
        {
            Label hits = (Label)sender;
            IDataItemContainer container = (IDataItemContainer)hits.NamingContainer;
            Facet facet = (Facet)container.DataItem;
            hits.Text = " (" + facet.Hits.ToString() + ")";
        }

        void link_DataBinding(object sender, EventArgs e)
        {
            LinkButton link = (LinkButton)sender;
            IDataItemContainer container = (IDataItemContainer)link.NamingContainer;
            Facet facet = (Facet)container.DataItem;
            if (facet.Name.Trim() == Constants.UNNAMED_FACET_VALUE.Trim()) link.Enabled = false;
                        
            //string propValue = facet.Name;
            if (facet.DisplayName.Length > _cropMax+3)
            {
                link.ToolTip = facet.Name;
                link.Text = facet.DisplayName.Remove(_cropMax) + "...";
            }
            else link.Text = facet.DisplayName;

            if (facet.DisplayName != facet.Name)
            {
                link.ToolTip = facet.Name;
            }

            link.CommandName = "SelectFacet";
            link.CommandArgument = facet.Hits.ToString();
        }
        #endregion
    }

    public class FacetLightTemplate : Control, INamingContainer, ITemplate
    {
        private ListItemType _type;
        private string _cssClass;
        private short _cropMax = 20;
        private string _key;
        private readonly string images_folder = Constants.IMAGES_FOLDER;
        private SearchQuery _query;
        
        
        public FacetLightTemplate(ListItemType type, string cssClass)
        {
            _type = type;
            _cssClass = cssClass;
        }

        public FacetLightTemplate(ListItemType type, SearchQuery query, string cssClass, short cropMax, string key)
        {
            _type = type;
            _query = query;
            _cssClass = cssClass;
            _cropMax = cropMax;
            _key = key;
        }

        #region ITemplate Members
        public void InstantiateIn(Control container)
        {
            HyperLink link = new HyperLink();
            link.CssClass = _cssClass;
            Label hits = new Label();
            //hits.CssClass = _cssClass;
            HtmlImage img = new HtmlImage();
            img.EnableViewState = false;
            img.Visible = false;
            img.Align = "absmiddle";
            img.Style.Add("MARGIN-RIGHT", "6px");

            switch (_type)
            {
                case ListItemType.Header:
                    break;
                case ListItemType.Item:
                    link.DataBinding += new EventHandler(link_DataBinding);
                    //container.Controls.Add(new LiteralControl("<li>"));
                    container.Controls.Add(new LiteralControl(@"
                        <table border=""0"" cellpadding=""0"" cellspacing=""0"" class=""" + _cssClass + @""" width=""100%"">
                            <tr>
                                <td nowrap=""nowrap"" width=""100%"" style=""vertical-align:middle"">"));
                    container.Controls.Add(img);
                    container.Controls.Add(link);
                    container.Controls.Add(hits);
                    container.Controls.Add(new LiteralControl(@"</td></tr></table>"));

                    img.DataBinding += new EventHandler(img_DataBinding);
                    hits.DataBinding += new EventHandler(hits_DataBinding);
                    //container.Controls.Add(new LiteralControl("</li>"));
                    break;
                case ListItemType.AlternatingItem:
                    break;
                case ListItemType.Footer:
                    break;
            }
        }

        void img_DataBinding(object sender, EventArgs e)
        {
            HtmlImage img = (HtmlImage)sender;
            IDataItemContainer container = (IDataItemContainer)img.NamingContainer;
            Facet facet = (Facet)container.DataItem;
            if (string.IsNullOrEmpty(facet.Image))
            {
                img.Visible = false;
            }
            else
            {
                img.Visible = true;
                img.Src = images_folder + facet.Image;
            }
        }

        void hits_DataBinding(object sender, EventArgs e)
        {
            Label hits = (Label)sender;
            IDataItemContainer container = (IDataItemContainer)hits.NamingContainer;
            Facet facet = (Facet)container.DataItem;
            hits.Text = " (" + facet.Hits.ToString() + ")";
        }

        void link_DataBinding(object sender, EventArgs e)
        {
            HyperLink link = (HyperLink)sender;
            IDataItemContainer container = (IDataItemContainer)link.NamingContainer;
            Facet facet = (Facet)container.DataItem;
            if (facet.Name.Trim() == Constants.UNNAMED_FACET_VALUE.Trim()) link.Enabled = false;
            
            //string propValue = facet.Name;
            if (facet.DisplayName.Length > _cropMax+3)
            {
                link.ToolTip = facet.Name;
                link.Text = HttpUtility.HtmlEncode(facet.DisplayName.Remove(_cropMax)) + "...";
            }
            else link.Text = HttpUtility.HtmlEncode(facet.DisplayName);

            if (facet.DisplayName != facet.Name)
            {
                link.ToolTip = facet.Name;
            }

            SearchQuery query = _query.Clone();
            query.Start = 1;
            query.Properties.Set(_key, facet.Name);
            string qs = Utility.BuildQueryString(query);
            string qsEncoded = string.Format("{0}?{1}", HttpContext.Current.Request.Url.AbsolutePath, qs);
            link.NavigateUrl = qsEncoded;

        }
        #endregion
    }

    /// <summary>
    /// Class defines templates used for bread crumb data binding
    /// </summary>
    public class CrumbTemplate : Control, INamingContainer, ITemplate
    {
        private ListItemType _type;
        private string _cssClass;
        private string _cssContainerClass;
        private SearchQuery _query;
        private short _cropMax;

        #region CTOR
        public CrumbTemplate(ListItemType type, string cssClass)
        {
            _type = type;
            _cssClass = cssClass;
        }
        public CrumbTemplate(ListItemType type, SearchQuery query, string cssClass, string cssContainerClass, short cropMax):this(type, cssClass)
        {
            _query = query;
            _cropMax = cropMax;
            _cssContainerClass = cssContainerClass;
        } 
        #endregion

        #region ITemplate Members
        public void InstantiateIn(Control container)
        {
            HyperLink link = new HyperLink();
            link.ImageUrl = "/_layouts/images/PTCLOSE.GIF";//filteroff.gif";
            link.EnableViewState = false;
            link.ToolTip = Resource.SEARCH_BREADCRUMBS_WEBPART_REMOVEFILTER; 
            
            HtmlAnchor facet = new HtmlAnchor();
            facet.Attributes.Add("class", _cssClass);
            facet.EnableViewState = false;

            HyperLink union = new HyperLink();
            union.ImageUrl = "/_layouts/images/NEWLINK.GIF";
            union.EnableViewState = false;
            union.ToolTip = Resource.SEARCH_BREADCRUMBS_WEBPART_UNIONFILTER; 
            
            switch (_type)
            {
                case ListItemType.Header:
                    break;
                case ListItemType.Item:
                    link.DataBinding += new EventHandler(link_DataBinding);
                    union.DataBinding += new EventHandler(union_DataBinding);
                    facet.DataBinding += new EventHandler(facet_DataBinding);
                    container.Controls.Add(new LiteralControl(@"
            <table border=""0"" style=""width:100%;border-collapse:collapse;"">
		        <tr>
			        <td class=""" + _cssContainerClass + @""" style=""width:100%;"">
                        <table border=""0"" cellpadding=""0"" cellspacing=""0"" class=""" + _cssClass + @""" width=""100%"" >
                            <tr valign=""middle"">
                                <td width=""100%"" nowrap=""nowrap"">"));
                    container.Controls.Add(facet);
                    container.Controls.Add(new LiteralControl(@"</td><td valign='bottom'>"));
                    container.Controls.Add(union);
                    container.Controls.Add(new LiteralControl(@"</td><td valign='bottom'>"));
                    container.Controls.Add(link);
                    container.Controls.Add(new LiteralControl(@"
                                </td>
                            </tr>
                        </table>   
                    </td>
                </tr>
            </table>                          
"));                 
                    break;
                case ListItemType.AlternatingItem:

                    break;
                case ListItemType.Footer:
                    break;
            }
        }

        void union_DataBinding(object sender, EventArgs e)
        {
            HyperLink union = (HyperLink)sender;
            IDataItemContainer container = (IDataItemContainer)union.NamingContainer;
            DataRow row = ((DataRowView)container.DataItem).Row;
            string facetName = row["FacetName"].ToString();
            string facetDisplayName = row["FacetDisplayName"].ToString();
            //string facetValue = row["FacetValue"].ToString();

            SearchQuery query = _query.Clone();
            string qs = string.Format("{0}?{1}", HttpContext.Current.Request.Url.AbsolutePath, Utility.BuildQueryString(query));
            union.Attributes.Add("onclick", string.Format("return addMatch(\"{0}\", \"{1}\", \"{2}\");", facetName, facetDisplayName, qs));
        }

        void facet_DataBinding(object sender, EventArgs e)
        {
            HtmlAnchor facet = (HtmlAnchor)sender;
            IDataItemContainer container = (IDataItemContainer)facet.NamingContainer;
            DataRow row = ((DataRowView)container.DataItem).Row;
            string facetName = row["FacetName"].ToString();
            string facetDisplayName = (string.IsNullOrEmpty(row["FacetDisplayName"].ToString())) ? facetName : row["FacetDisplayName"].ToString();
            if (facetDisplayName.Length > _cropMax+3)
            {
                facet.Attributes.Add("title", facetDisplayName);
                facet.InnerText = HttpUtility.HtmlEncode(facetDisplayName.Remove(_cropMax)) + "...";
            }
            else facet.InnerText = HttpUtility.HtmlEncode(facetDisplayName);
        }

        void link_DataBinding(object sender, EventArgs e)
        {
            HyperLink link = (HyperLink)sender;
            IDataItemContainer container = (IDataItemContainer)link.NamingContainer;
            DataRow row = ((DataRowView)container.DataItem).Row;
            string facetName = row["FacetName"].ToString();
            //string facetValue = row["FacetValue"].ToString();
            
            SearchQuery query = _query.Clone();
            query.Properties.Remove(facetName);
            
            string qs = string.Format("{0}?{1}", HttpContext.Current.Request.Url.AbsolutePath, Utility.BuildQueryString(query));
            link.NavigateUrl = qs;
        }

        #endregion
    }

    /// <summary>
    /// Class defines templates used for bread crumb data binding
    /// </summary>
    public class CrumbFacetTemplate : Control, INamingContainer, ITemplate
    {
        private ListItemType _type;
        private string _cssClass;
        private string _cssClassCrumb;
        private string _cssClassCrumbHover;
        private string _facetName;
        private SearchQuery _query;
        private short _cropMax = 10;

        #region CTOR
        public CrumbFacetTemplate(ListItemType type, string cssClass, string facetName)
        {
            _type = type;
            _cssClass = cssClass;
            _facetName = facetName;
        }
        public CrumbFacetTemplate(ListItemType type, SearchQuery query, string cssClass, string facetName, string cssClassCrumb, string cssClassCrumbHover, short cropMax)
            : this(type, cssClass, facetName)
        {
            _query = query;
            _cssClassCrumb = (string.IsNullOrEmpty(cssClassCrumb)) ? "ms-consoleqaback" : cssClassCrumb;
            _cssClassCrumbHover = (string.IsNullOrEmpty(cssClassCrumbHover)) ? "ms-consoleqabackhover" : cssClassCrumbHover; ;
            _cropMax = cropMax;
        }
        #endregion

        #region ITemplate Members
        public void InstantiateIn(Control container)
        {
            HyperLink link = new HyperLink();
            link.ImageUrl = "/_layouts/images/BROKENLINK.GIF";
            link.ToolTip = Resource.SEARCH_BREADCRUMBS_WEBPART_REMOVEUNION;
            link.EnableViewState = false;
            Label facet = new Label();
            facet.EnableViewState = false;

            switch (_type)
            {
                case ListItemType.Header:
                    break;
                case ListItemType.Item:
                    link.DataBinding += new EventHandler(link_DataBinding);
                    facet.DataBinding += new EventHandler(facet_DataBinding);
                    container.Controls.Add(new LiteralControl(@"
    <table cellpadding=""0"" cellspacing=""0"" border=""0"" width=""100%"">
       <tr>
            <td class=""ms-consoleqaemptycorner""></td>
            <td class=""ms-consoleqaemptycorner""></td>
            <td class=""ms-consoleqaborderh""></td>
            <td class=""ms-consoleqaemptycorner""></td>
            <td class=""ms-consoleqaemptycorner""></td>
        </tr>
        <tr>
            <td class=""ms-consoleqaemptycorner""></td>
            <td class=""ms-consoleqacorner""></td>
            <td>
                <table cellspacing=""0"" border=""0"" cellpadding=""0"" width=""100%"">
                    <tr><td class=""ms-consoleqaemptyborderh""></td></tr>
                </table>
            </td>
            <td class=""ms-consoleqacorner""></td>
            <td class=""ms-consoleqaemptycorner""></td>
        </tr>
        <tr>
            <td class=""ms-consoleqaborderv"">
            </td>
            <td class=""ms-consoleqaemptyborderv"">
            </td>
            <td>
                <table width=""100%"" cellpadding=""0"" cellspacing=""0"" border=""0"" onmouseover=""this.className='" + _cssClassCrumbHover + @"';try{DeferCall('showQAButtonHover', this, true);}catch(e){}""
                    onmouseout=""this.className='" + _cssClassCrumb + @"';try{DeferCall('showQAButtonHover', this, false);}catch(e){}""
                    class='" + _cssClassCrumb + @"'>
                    <tr>
                        <td valign=""middle"" nowrap style=""height:20px"" width=""100%"">
"));
                    container.Controls.Add(new LiteralControl(string.Format(@"<SPAN class=""{0}"">", _cssClass)));
                    container.Controls.Add(facet);
                    container.Controls.Add(new LiteralControl(@"</SPAN>"));
                    container.Controls.Add(new LiteralControl(@"</td><td valign=""middle"" nowrap>"));
                    //container.Controls.Add(new LiteralControl(string.Format(@"<SPAN class=""{0}"">", _cssClass)));
                    container.Controls.Add(link);
                    //container.Controls.Add(new LiteralControl(@"</SPAN>"));
                    container.Controls.Add(new LiteralControl(@"
        </td>
                        </tr>
                </table>
            </td>
            <td class=""ms-consoleqaemptyborderv""></td>
            <td class=""ms-consoleqaborderv"" ></td>
        </tr>
        <tr>
            <td class=""ms-consoleqaemptycorner""></td>
            <td class=""ms-consoleqacorner""></td>
            <td class=""ms-consoleqaemptyborderh""></td>
            <td class=""ms-consoleqacorner""></td>
            <td class=""ms-consoleqaemptycorner""></td>
        </tr>
        <tr>
            <td class=""ms-consoleqaemptycorner""></td>
            <td class=""ms-consoleqaemptycorner""></td>
            <td class=""ms-consoleqaborderh""></td>
            <td class=""ms-consoleqaemptycorner""></td>
            <td class=""ms-consoleqaemptycorner""></td>
        </tr>   
    </table>

"));



                    break;
                case ListItemType.AlternatingItem:
                    break;
                case ListItemType.Footer:
                    break;
            }
        }

        void facet_DataBinding(object sender, EventArgs e)
        {
            Label facet = (Label)sender;
            IDataItemContainer container = (IDataItemContainer)facet.NamingContainer;
            DataRow row = ((DataRowView)container.DataItem).Row;
            string facetValue = row["FacetValue"].ToString();
            string facetDisplayValue = row["FacetDisplayValue"].ToString();
            if (facetDisplayValue.Length > _cropMax+3)
            {
                facet.ToolTip = facetDisplayValue;
                facet.Text = HttpUtility.HtmlEncode(facetDisplayValue.Remove(_cropMax)) + "...";
            }
            else facet.Text = HttpUtility.HtmlEncode(facetDisplayValue);
        }

        void link_DataBinding(object sender, EventArgs e)
        {
            HyperLink link = (HyperLink)sender;
            IDataItemContainer container = (IDataItemContainer)link.NamingContainer;
            DataRow row = ((DataRowView)container.DataItem).Row;
            string facetValue = row["FacetValue"].ToString();
            string facetDisplayValue = row["FacetDisplayValue"].ToString();
            
            // provision for multiple values for the facet
            SearchQuery query = _query.Clone();
            if (_query.Properties[_facetName].Contains(Splitter.Delimiter))
            {
                ArrayList alTmp = new ArrayList(_query.Properties[_facetName].Split(Splitter.UniDelimiter, StringSplitOptions.RemoveEmptyEntries));
                alTmp.Remove(facetValue);
                string tmp = Splitter.Join(alTmp, Splitter.Delimiter);
                query.Properties[_facetName] = tmp;
            }
            else
            {
                query.Properties.Remove(_facetName);
            }
            string qs = string.Format("{0}?{1}", HttpContext.Current.Request.Url.AbsolutePath, Utility.BuildQueryString(query));
            link.NavigateUrl = qs;
        }

        #endregion
    }


    /// <summary>
    /// Class defines templates used for bread crumb separation
    /// </summary>
    public class SeparatorTemplate : Control, INamingContainer, ITemplate
    {
        private ListItemType _type;
        private string _separator;
        private string _cssClass;

        public SeparatorTemplate(ListItemType type, string cssClass, string separator)
        {
            _type = type;
            _cssClass = cssClass;
            _separator = separator;
        }

        #region ITemplate Members
        public void InstantiateIn(Control container)
        {
            LiteralControl sep = new LiteralControl();
            sep.EnableViewState = false;
            sep.Text = _separator;
            //sep.CssClass = _cssClass;
            switch (_type)
            {
                case ListItemType.Header:
                    break;
                case ListItemType.Separator:
                    container.Controls.Add(sep);
                    break;
                case ListItemType.AlternatingItem:
                    break;
                case ListItemType.Footer:
                    break;
            }
        }
        #endregion
    }

    /// <summary>
    /// Class defines templates used for bread crumb displayName
    /// </summary>
    public class HeaderTemplate : Control, INamingContainer, ITemplate
    {
        #region fields
        private ListItemType _type;
        private string _cssClass;
        private string _name;
        private string _displayName;
        private string _toolTip;
        private int _totalResults;
        private int _count;
        private bool _displayProgress; 
        #endregion

        public HeaderTemplate(ListItemType type, string cssClass, string name, string displayName, string toolTip, int totalResults, int count, bool displayProgress)
        {
            _type = type;
            _cssClass = cssClass;
            _name = name;
            _displayName = displayName;
            _toolTip = toolTip;
            _totalResults = totalResults;
            _count = count;
            _displayProgress = displayProgress;

        }

        #region ITemplate Members
        public void InstantiateIn(Control container)
        {
            HyperLink displayName = new HyperLink();
            displayName.EnableViewState = false;
            displayName.Text = _displayName;
            //displayName.ToolTip = _toolTip;
            displayName.CssClass = _cssClass;

            Image icon = new Image();
            icon.ImageUrl = "/_layouts/images/DeployReportInfo.gif";
            icon.ToolTip = _toolTip;
            icon.EnableViewState = false;

            HyperLink scroll = new HyperLink();
            scroll.EnableViewState = false;
            scroll.ImageUrl = "/_layouts/images/DLMAX.gif";
            scroll.NavigateUrl = "#";
            scroll.Width = scroll.Height = Unit.Pixel(13);
            scroll.Attributes.Add("facet", _displayName);
            scroll.Text = Resource.SEARCH_FACETS_EXPANDMENU_LINK;
            scroll.Attributes.Add("onclick", "switchFooter(this, '" + _name + "', " + _totalResults + "); return false;");

            Image progress = new Image();
            progress.EnableViewState = false;
            progress.ID = "Progress";
            progress.Attributes.Add("progress", _displayProgress.ToString());
            progress.Width = Unit.Pixel(63);
            progress.Height = Unit.Pixel(12);
            //progress.ImageAlign = ImageAlign.Right | ImageAlign.Middle;
            progress.ImageUrl = (_displayProgress) ? "/_layouts/images/kpiprogressbar.gif" : "/_layouts/images/blank.gif";
            progress.AlternateText = progress.ToolTip;
            progress.ToolTip = string.Format("refining facets", "");

            switch (_type)
            {
                case ListItemType.Header:
                    container.Controls.Add(new LiteralControl(@"
                        <table border=""0"" cellpadding=""0"" cellspacing=""0"" class=""" + _cssClass + @""" width=""100%"" >
                            <tr valign=""middle"">
                                <td width=""100%"" nowrap=""nowrap"">"));
                    container.Controls.Add(displayName);
                    container.Controls.Add(new LiteralControl(@"</td><td valign='middle'>"));
                    if (_displayProgress)
                    {
                        container.Controls.Add(progress);
                        container.Controls.Add(new LiteralControl(@"</td><td>"));
                    }
                    if (_totalResults > 1)
                    {
                        container.Controls.Add(scroll);
                    }
                    else
                    {
                        HtmlImage empty = new HtmlImage();
                        empty.Width = empty.Height = 13;
                        empty.Src = "/_layouts/images/blank.gif";
                        container.Controls.Add(empty);
                    }
                    container.Controls.Add(new LiteralControl(@"</td><td>"));
                    container.Controls.Add(icon);
                    container.Controls.Add(new LiteralControl(@"</td></tr></table>"));
                    
                    break;
                case ListItemType.Separator:
                    break;
                case ListItemType.AlternatingItem:
                    break;
                case ListItemType.Footer:
                    break;
            }
        }
        #endregion
    }

    /// <summary>
    /// Class defines templates used for bread crumb displayName
    /// </summary>
    public class FooterTemplate : Control, INamingContainer, ITemplate
    {
        private ListItemType _type;
        private string _cssClass;
        private string _footer;
        private int _totalResults;

        public FooterTemplate(ListItemType type, string cssClass, string footer, int totalResults)
        {
            _type = type;
            _cssClass = cssClass;
            _footer = footer;
            _totalResults = totalResults;
        }

        #region ITemplate Members
        public void InstantiateIn(Control container)
        {        
            Label more = new Label();
            more.EnableViewState = false;
            more.Text = "...";
            
            switch (_type)
            {
                case ListItemType.Footer:
                    container.Controls.Add(new LiteralControl(@"
                        <table border=""0"" cellpadding=""0"" cellspacing=""0"" class=""" + _cssClass + @""" width=""100%"">
                            <tr>
                                <td width=""100%"">...</td></tr></table>"));
                    break;
                case ListItemType.Separator:
                    break;
                case ListItemType.AlternatingItem:
                    break;
                case ListItemType.Header:
                    break;
            }
        }
        #endregion
    }
}
